home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / e / ProgSuite.lha / ProgSuite / Defs.e < prev    next >
Text File  |  1996-09-09  |  3KB  |  90 lines

  1. /* Definitions - included in all ProgSuite programs (V1.0) */
  2.  
  3. OPT MODULE
  4. OPT EXPORT
  5.  
  6. MODULE 'intuition/intuition', 'intuition/screens', 'graphics/view'
  7. MODULE 'tools/ilbm', 'tools/ilbmdefs'
  8. MODULE 'amigalib/ports', 'dos/dos'
  9. MODULE 'exec/memory', 'exec/nodes', 'exec/ports'
  10.  
  11. /* Exception values */
  12.  
  13. ENUM ERR_NONE, ERR_FINDSCREEN, ERR_FINDPORT
  14.  
  15. /* Automatic Exceptions */
  16.  
  17. RAISE    "WIN"        IF OpenW () = NIL,
  18.     "SCR"        IF OpenS () = NIL,
  19.     ERR_FINDSCREEN     IF LockPubScreen () = NIL
  20.  
  21. /* Message types and structure */
  22.  
  23. ENUM WAKEMSG, FINISHMSG, QUITDISPLMSG, QUITCONTRMSG, QUITWORLDMSG
  24.  
  25. OBJECT portMessage
  26.   msg: mn
  27.   msc: LONG
  28.   msn: INT
  29. ENDOBJECT
  30.  
  31. /* Common Procedures */
  32.  
  33. PROC portCreate (portname: PTR TO mp, progname: PTR TO CHAR) HANDLE
  34. DEF newport: PTR TO mp
  35.   IF NIL = (newport := createPort (portname, 0)) THEN Raise ("PORT")
  36. EXCEPT DO
  37.   SELECT exception
  38.   CASE "PORT"
  39.     WriteF ('\s: Couldn''t create messageport "\s"!\n', progname, portname)
  40.     ReThrow ()
  41.   ENDSELECT
  42. ENDPROC newport
  43.  
  44. PROC portRemove (msgport: PTR TO mp)
  45. DEF portmsg: PTR TO portMessage
  46.   -> Make sure the port is empty before deleting it
  47.   WHILE portmsg := GetMsg (msgport) DO messageReply (portmsg, msgport)
  48.   deletePort (msgport)
  49. ENDPROC
  50.  
  51. PROC messageCreate (replyport: PTR TO mp, progname: PTR TO CHAR) HANDLE
  52. DEF newmessage: PTR TO portMessage
  53.   newmessage := NewM (SIZEOF portMessage, MEMF_PUBLIC OR MEMF_CLEAR)
  54.   newmessage.msg.ln.type := NT_MESSAGE         -> Make up a message, including the
  55.   newmessage.msg.length := SIZEOF portMessage  -> reply port.
  56.   newmessage.msg.replyport := replyport
  57.   newmessage.msc := 0                          -> i.e. this is NOT an IntuiMessage
  58. EXCEPT DO
  59.   SELECT exception
  60.   CASE "MEM"
  61.     WriteF ('\s: Couldn''t create port message!\n', progname)
  62.     ReThrow ()
  63.   ENDSELECT
  64. ENDPROC newmessage
  65.  
  66. PROC messageSend (message: PTR TO portMessage, portname: PTR TO mp)
  67. DEF port: PTR TO mp
  68.   Forbid ()
  69.   port := FindPort (portname)
  70.   IF port THEN PutMsg (port, message)
  71.   Permit ()
  72. ENDPROC port <> NIL    -> Returns FALSE if the port was not found
  73.  
  74. PROC messageReply (message: PTR TO portMessage, ownportname: PTR TO mp)
  75. DEF result = FALSE
  76.   IF (message.msg.replyport <> NIL) AND (message.msg.replyport <> ownportname)
  77.     WriteF ('messageReply: replying message \d \d\n', message.msc, message.msn)
  78.     ReplyMsg (message)
  79.     result := TRUE
  80.   ENDIF
  81. ENDPROC result        -> Returns FALSE if it was our own message
  82.  
  83. PROC messageCheckOwn (message: PTR TO portMessage, ownportname: PTR TO mp, progname: PTR TO CHAR)
  84.   IF message.msg.replyport = ownportname
  85.     WriteF ('\s: Reply received: \d \d\n', progname, message.msc, message.msn)
  86.   ELSE
  87.     WriteF ('\s: Message received: \d \d\n', progname, message.msc, message.msn)
  88.   ENDIF
  89. ENDPROC
  90.